namespace Y190625_Stack {
int main();

#include <assert.h>

template<class T>
class abstack {
public:
	bool isEmpty()
	{
		return (height == 0) ? true : false;
	}
	virtual void push(T&) = 0;
	virtual bool pop(T&) = 0;
	virtual void clear() = 0;

protected:
	unsigned height;
};

template<class T>
class SeqStack : public abstack<T> {
public:
	SeqStack(int i = 10);
	SeqStack(SeqStack& s)
	{
		copy(s);
	}
	~SeqStack()
	{
		clear();
	}
	void push(T& x);
	bool pop(T& x);
	void clear() {
		if (elements) {
			delete elements;
			elements = nullptr;
			this->height = 0;
		}
	}
	SeqStack& copy(SeqStack& s);
	SeqStack& operator=(SeqStack& s) {
		clear();
		copy(s);
		return *this;
	}
	bool isFull()const {
		return top == maxsize - 1;
	}
protected:
	int top;
	T* elements;
	int maxsize;
};

template<class T>
SeqStack<T>::SeqStack(int i)
{
	this->height = 0;
	top = -1;
	maxsize = i > 10 ? i : 10;
	elements = new T[maxsize];
	assert(elements);
}

template<class T>
void SeqStack<T>::push(T& x)
{
	assert(!isFull());
	elements[++top] = x;
	this->height++;
}

template<class T>
bool SeqStack<T>::pop(T& x)
{
	if (this->isEmpty())
	{
		return false;
	}
	else {
		x = elements[top--];
		this->height--;
	}
	return true;
}

template<class T>
SeqStack<T> & SeqStack<T>::copy(SeqStack& s)
{
	maxsize = s.maxsize;
	if(elements==NULL)
		elements = new T[maxsize];
	assert(elements);
	int len = s.height;
	for (int i = 0; i < len; i++)
		elements[i] = *(s.elements + i);
	top = s.top;
	this->height = s.height;
	return *this;
}

int main()
{
	return 0;
}
}

int main()
{
	return Y190625_Stack::main();
}
